package com.liumuxian.video.service.impl;

import com.liumuxian.video.dao.*;
import com.liumuxian.video.pojo.*;
import com.liumuxian.video.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import util.IdWorker;
import javax.annotation.Resource;
import java.util.*;

@Service
@Transactional
public class VideoServiceImpl implements VideoService{
    @Resource
    private VideoDao videoDao;
    @Resource
    private IdWorker idWorker;
    @Autowired
    private VideoTemplatesetDao videoTemplatesetDao;

    @Override
    public void save(Video video) {
        video.setId(idWorker.nextId()+"");
        videoDao.save(video);
    }

    @Override
    public void update(Video video){
        videoDao.update(video.getType(),video.getPrice(),video.getCount(),video.getState(),
        video.getCreatdata(),video.getUpdatedate(),video.getId());
    }

    @Override
    public List<Video> findAllByState(Integer state) {
        return videoDao.findAllByState(state);
    }

    @Override
    public Video getOne(String vid) {
        return videoDao.getOne(vid);
    }

    public List<Video> findByTemAndVideo(String tid) {
       List<VideoTemplateset> list = videoTemplatesetDao.findAllByTemplatesetid(tid);
       Set<String> vid = new HashSet<>();
       list.forEach(l ->vid.add(l.getVideoid()));
       return videoDao.findAllByIdInAndState(vid,1);
    }
}
